export function is(val, type) {
	const toString = Object.prototype.toString;
	return toString.call(val) === `[object ${type}]`;
}

export function isDef(val) {
	return typeof val !== "undefined";
}

export function isUndef(val) {
	return typeof val === "undefined";
}

export function isNull(val) {
  return val === null;
}

export function isNullOrUndef(val) {
  return isNull(val) || isUndef(val);
}

export function isObject(val) {
	return !isNull(val) && is(val, "Object");
}

export function isArray(val) {
	return val && Array.isArray(val);
}

export function isString(val) {
	return is(val, "String");
}

export function isNumber(val) {
  return is(val, "Number");
}

export function isBoolean(val) {
  return is(val, "Boolean");
}

export function isDate(val) {
  return is(val, "Date");
}

export function isRegExp(val) {
  return is(val, "RegExp");
}

export function isFunction(val) {
  return typeof val === "function";
}

/** 空数组 | 空字符串 | 空对象 | 空Map | 空Set */
export function isEmpty(val) {
  if (isArray(val) || isString(val)) {
    return val.length === 0;
  }

  if (val instanceof Map || val instanceof Set) {
    return val.size === 0;
  }

  if (isObject(val)) {
    return Object.keys(val).length === 0;
  }

  return false;
}